package com.huihui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.huihui.R;
import com.huihui.bean.Goods;
import com.huihui.bean.MinePingLun;
import com.huihui.datamanager.AppManager;
import com.huihui.network.HttpContants;
import com.huihui.network.OkHttpRequest;
import com.huihui.network.base.CallBackUtil;
import com.huihui.utils.LoadImageUtil;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;
import okhttp3.Call;

/**
 * Created by Administrator on 2018/8/18.
 */

public class MineMsgZanAdapter extends RecyclerView.Adapter<ItemViewHolder1> {

    private Context context;
    private List<MinePingLun> list;

    public MineMsgZanAdapter(Context context, List<MinePingLun> list) {
        this.context = context;
        this.list = list;
    }


    @Override
    public com.huihui.adapter.ItemViewHolder1 onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_mine_msg_zan, parent, false);
        return new com.huihui.adapter.ItemViewHolder1(view);
    }

    @Override
    public void onBindViewHolder(ItemViewHolder1 holder, int position) {
        MinePingLun mineZan = list.get(position);
        if (mineZan != null) {
            //设置数据
//            LoadImageUtil.displayImage(context,mineZan.getSend_user_headimg(),holder.send_user_headimg);
            //评论人
            LoadImageUtil.displayImage(context, mineZan.getSend_user_headimg(), holder.head_view);
            holder.send_user_nickname.setText(mineZan.getSend_user_nickname() + mineZan.getAction_name());
            holder.msg_time.setText(mineZan.getMsg_time());
            String reply_comment = mineZan.getReply_comment();
            if (TextUtils.isEmpty(reply_comment)) {
                holder.current_content.setVisibility(View.GONE);
            } else {
                holder.current_content.setVisibility(View.VISIBLE);
                holder.current_content.setText(reply_comment);
            }
            int class_id = mineZan.getClass_id();
            if (class_id == 1) {
                holder.zan_playIcon.setVisibility(View.VISIBLE);
            } else {
                holder.zan_playIcon.setVisibility(View.GONE);
            }
            //作者
            LoadImageUtil.displayImage(context, mineZan.getAuthor_headimg(), holder.author_headimg);
            holder.author_nickname.setText(mineZan.getAuthor_nickname());
            holder.author_conent.setText(mineZan.getAuthor_conent());
            if (onDianZanListener != null) {
                holder.zan_icon.setTag(position);
                holder.zan_icon.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        int p = (int) v.getTag();
                        onDianZanListener.onClick(p);
                        ((ImageView) v).setImageResource(R.mipmap.zan_press);
                    }
                });
            }
            holder.replayId.setVisibility(View.GONE);
            if(onDianZanListener != null){
                holder.replayId.setTag(position);
                holder.replayId.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        int p = (int) v.getTag();
                        onDianZanListener.onClick(p);
                    }
                });
            }

        }
    }


    @Override
    public int getItemCount() {

        return list == null ? 0 : list.size();
    }

    public interface OnDianZanListener {
        void onClick(int position);
    }

    private OnDianZanListener onDianZanListener;

    public void setOnDianZanClickListener(OnDianZanListener listener) {
        this.onDianZanListener = listener;
    }

}
